{% extends 'teachers/base.html' %}
{% block teachers_index %}
    <br>
    <div class="container">
        <div class="col-8 offset-2" style="border: 1px solid #4f4848;border-radius: 15px;
        background-color: rgba(169,162,162,0.05);">
            <div style="margin: 30px 30px 30px 30px ">
                <div class="text-center">
                    <h4 style="">{{ exercises.exercises }}</h4>
                </div>
                {#        for 语句#}
                <div class="col-12">
                    {% for i in ansewer %}

                        <div>

                            <div class="row">
                                <div class="col-10">
                                    <h5 class="form-label"><span class="badge rounded-pill bg-success">{{ forloop.counter }}</span>&emsp;{{ i.title }}</h5>
                                </div>
                                <div class="col-2">

                                    <button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal"
                                            data-bs-target="#exampleModal_edit_{{ i.id }}">
                                        修改
                                    </button>

                                    <!-- Modal -->
                                    <div class="modal fade" id="exampleModal_edit_{{ i.id }}" tabindex="-1"
                                         aria-labelledby="exampleModalLabel" aria-hidden="true">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="exampleModalLabel">修改题目</h5>
                                                    <button type="button" class="btn-close" data-bs-dismiss="modal"
                                                            aria-label="Close"></button>
                                                </div>
                                                <form action="{% url 'ansewer_edit' exercises.id i.id %}" method="post">
                                                    {% csrf_token %}
                                                    <div class="modal-body">
                                                        <div class="mb-3">
                                                            <label for="exampleInputPassword1"
                                                                   class="form-label">题目</label>
                                                            <textarea required type="text" name="title"
                                                                      class="form-control"
                                                                      id="exampleInputPassword1">{{ i.title }}</textarea>
                                                        </div>
                                                        <div class="mb-3">
                                                            <label for="exampleInputPassword1"
                                                                   class="form-label">答案A</label>
                                                            <input required type="text" name="a" class="form-control"
                                                                   id="exampleInputPassword1" value="{{ i.answerA }}">
                                                        </div>
                                                        <div class="mb-3">
                                                            <label for="exampleInputPassword1"
                                                                   class="form-label">答案B</label>
                                                            <input required type="text" name="b" class="form-control"
                                                                   id="exampleInputPassword1" value="{{ i.answerB }}">
                                                        </div>
                                                        <div class="mb-3">
                                                            <label for="exampleInputPassword1"
                                                                   class="form-label">答案C</label>
                                                            <input required type="text" name="c" class="form-control"
                                                                   id="exampleInputPassword1" value="{{ i.answerC }}">
                                                        </div>
                                                        <div class="mb-3">
                                                            <label for="exampleInputPassword1"
                                                                   class="form-label">答案D</label>
                                                            <input required type="text" name="d" class="form-control"
                                                                   id="exampleInputPassword1" value="{{ i.answerD }}">
                                                        </div>
                                                        <div class="mb-3">
                                                            <label for="exampleInputPassword1"
                                                                   class="form-label">正确答案</label>
                                                            <select required class="form-select" name="e"
                                                                    aria-label="Default select example">

                                                                <option selected>请选择正确答案</option>
                                                                <option value="1">A</option>
                                                                <option value="2">B</option>
                                                                <option value="3">C</option>
                                                                <option value="4">D</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-secondary"
                                                                data-bs-dismiss="modal">取消
                                                        </button>
                                                        <button type="submit" class="btn btn-primary">确定</button>
                                                    </div>

                                                </form>
                                            </div>
                                        </div>
                                    </div>

                                    <button type="button" class="btn btn-sm btn-danger " data-bs-toggle="modal"
                                            data-bs-target="#staticBackdrop_del_{{ i.id }}">
                                        删除
                                    </button>

                                    <!-- Modal -->
                                    <div class="modal fade" id="staticBackdrop_del_{{ i.id }}" data-bs-backdrop="static"
                                         data-bs-keyboard="false"
                                         tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="staticBackdropLabel">确定删除吗？</h5>
                                                    <button type="button" class="btn-close" data-bs-dismiss="modal"
                                                            aria-label="Close"></button>
                                                </div>
                                                <div class="modal-body text-start">
                                                    确定删除“{{ i.title }}”吗？
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-secondary"
                                                            data-bs-dismiss="modal">取消
                                                    </button>
                                                    <a href="{% url 'ansewer_del' exercises.id i.id %}" type="button"
                                                       class="btn btn-danger">确定删除</a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                            </div>


                        </div>
                        <div style="margin-left: 30px">
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="flexRadioDefault"
                                       id="flexRadioDefault-a-{{ i.id }}">
                                <label class="form-check-label" for="flexRadioDefault-a-{{ i.id }}">
                                    A.{{ i.answerA }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="flexRadioDefault"
                                       id="flexRadioDefault-b-{{ i.id }}">
                                <label class="form-check-label" for="flexRadioDefault-b-{{ i.id }}">
                                    B.{{ i.answerB }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="flexRadioDefault"
                                       id="flexRadioDefault-c-{{ i.id }}">
                                <label class="form-check-label" for="flexRadioDefault-c-{{ i.id }}">
                                    C.{{ i.answerC }}
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="flexRadioDefault"
                                       id="flexRadioDefault-d-{{ i.id }}">
                                <label class="form-check-label" for="flexRadioDefault-d-{{ i.id }}">
                                    D.{{ i.answerD }}
                                </label>
                            </div>

                            <br>
                            <div class="mb-3">
                                <h6 style="color: #af4b4b">正确答案：
                                    {% if i.correctAnswer == 1 %}
                                        A
                                    {% elif i.correctAnswer == 2 %}
                                        B
                                    {% elif i.correctAnswer == 3 %}
                                        C
                                    {% elif i.correctAnswer == 4 %}
                                        D
                                    {% endif %}
                                </h6>

                            </div>
                        </div>
                        {% empty %}
                        <div class="text-center " style="height: 150px;">
                            <h4 style="margin-top: 50px;color: #1c51a1">请添加题！</h4>
                        </div>


                    {% endfor %}


                </div>
            </div>

        </div>
        <div class=" col-10 text-end" style="margin-top: 30px">

            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
                添加题
            </button>
        </div>
        <!-- Button trigger modal -->


        <!-- Modal -->
        <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">添加新题</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <form action="{% url 'ansewer_add' exercises.id %}" method="post">
                        {% csrf_token %}
                        <div class="modal-body">
                            <div class="mb-3">
                                <label for="exampleInputPassword1" class="form-label">题目</label>
                                <textarea required type="text" name="title" class="form-control"
                                          id="exampleInputPassword1"></textarea>
                            </div>
                            <div class="mb-3">
                                <label for="exampleInputPassword1" class="form-label">答案A</label>
                                <input required type="text" name="a" class="form-control" id="exampleInputPassword1">
                            </div>
                            <div class="mb-3">
                                <label for="exampleInputPassword1" class="form-label">答案B</label>
                                <input required type="text" name="b" class="form-control" id="exampleInputPassword1">
                            </div>
                            <div class="mb-3">
                                <label for="exampleInputPassword1" class="form-label">答案C</label>
                                <input required type="text" name="c" class="form-control" id="exampleInputPassword1">
                            </div>
                            <div class="mb-3">
                                <label for="exampleInputPassword1" class="form-label">答案D</label>
                                <input required type="text" name="d" class="form-control" id="exampleInputPassword1">
                            </div>
                            <div class="mb-3">
                                <label for="exampleInputPassword1" class="form-label">正确答案</label>
                                <select required class="form-select" name="e" aria-label="Default select example">

                                    <option selected>请选择正确答案</option>
                                    <option value="1">A</option>
                                    <option value="2">B</option>
                                    <option value="3">C</option>
                                    <option value="4">D</option>
                                </select>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">确定</button>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>

{% endblock %}
